package com.softer.wxzj.service.impl;

import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.enums.*;
import com.softer.wxzj.common.error.CourseException;
import com.softer.wxzj.common.flow.enums.FlowStateEnum;
import com.softer.wxzj.common.flow.enums.FlowTypeEnum;
import com.softer.wxzj.common.flow.util.FlowAddAuditUtil;
import com.softer.wxzj.common.flow.util.FlowAuditUtil;
import com.softer.wxzj.common.flow.util.Result;
import com.softer.wxzj.common.logic.CalculateAmount;
import com.softer.wxzj.common.util.*;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.mapper.*;
import com.softer.wxzj.service.DepModeInfoService;
import com.softer.wxzj.service.DepositContinuationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Gong Zhiyang
 * @date 2020/8/5
 */
@Service
public class DepositContinuationServiceImpl implements DepositContinuationService {
    @Autowired
    private DepositContinuationMapper depositContinuationMapper;
    @Autowired
    private OperUtil zoneCodeUtil;
    @Autowired
    private SysCoreParamMapper syscoreparamMapper;
    @Autowired
    private DepModeInfoService depModeInfoService;
    @Autowired
    private BaseBuildInfoMapper baseBuildInfoMapper;
    @Autowired
    private BaseHouseInfoMapper baseHouseInfoMapper;
    @Autowired
    private CalculateAmount calculateAmount;
    @Autowired
    private BaseHouseInfoServiceImpl baseHouseInfoService;
    @Autowired
    private FlowAddAuditUtil flowAddAuditUtil;
    @Autowired
    private DepReqListInfoMapper depReqListInfoMapper;
    @Autowired
    private DepReqMapper depReqMapper;
    @Autowired
    private AccKeepAccountMapper accKeepAccountMapper;
    @Autowired
    private DepModeInfoMapper depModeInfoMapper;
    @Autowired
    private FlowAuditUtil flowUtil;
    @Autowired
    private Result result;
    @Autowired
    private DepositAuditMapper depositAuditMapper;
    @Autowired
    private DepositApplyServiceImpl depositApplyService;

    private String getRate() {
        String rate = "0.3";
        SysCoreParam reservedRatioSysParam = syscoreparamMapper.getInfo(NumStrEnum.SEVEN.getNum());
        if (reservedRatioSysParam == null) {
            return rate;
        }
        //预留比例，默认0.3
        return reservedRatioSysParam.getParamCode() != null ? reservedRatioSysParam.getParamCode() : rate;

    }

    /**
     * 查询续交小区列表
     *
     * @param page           分页信息
     * @param baseRegionInfo 查询信息
     * @return 续交小区列表
     */
    @Override
    public PageInfo<BaseRegionInfo> getContinuationRegionList(Page page, BaseRegionInfo baseRegionInfo) {
        //赋值区域,重要
        baseRegionInfo.setLoginZoneCode(zoneCodeUtil.getZoneCode());
        String ratio = getRate();
        baseRegionInfo.setRate(new BigDecimal(ratio));
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseRegionInfo> list = depositContinuationMapper.getContinuationRegionList(baseRegionInfo);
        PageInfo<BaseRegionInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 查询续交自然幢列表
     *
     * @param page          分页信息
     * @param baseBuildInfo 查询信息
     * @return 续交自然幢列表
     */
    @Override
    public PageInfo<BaseBuildInfo> getContinuationBuildList(Page page, BaseBuildInfo baseBuildInfo) {
        String ratio = getRate();
        baseBuildInfo.setRate(new BigDecimal(ratio));
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseBuildInfo> list = depositContinuationMapper.getContinuationBuildList(baseBuildInfo);
        PageInfo<BaseBuildInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 批量查询续交房屋列表
     *
     * @param page          分页信息
     * @param baseHouseInfo 查询信息
     * @return 续交房屋列表
     */
    @Override
    public PageInfo<BaseHouseInfo> getContinuationHouseList(Page page, BaseHouseInfo baseHouseInfo) {
        String ratio = getRate();
        baseHouseInfo.setRate(new BigDecimal(ratio));
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseHouseInfo> list = depositContinuationMapper.getContinuationHouseList(baseHouseInfo);
        for (BaseHouseInfo b : list) {
            DepModeInfo depModeInfo = new DepModeInfo();
            depModeInfo.setHouseId(b.getId());
            depModeInfo.setHouseType(b.getHouseAttr());
            depModeInfo.setModeType(NumStrEnum.TWO.getNum());
            b.setDepModeInfos(depModeInfoService.selectByAllChange(depModeInfo));
        }
        PageInfo<BaseHouseInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 查询单个自然幢续交房屋列表
     *
     * @param page          分页信息
     * @param baseHouseInfo 查询信息
     * @return 续交房屋列表
     */
    @Override
    public PageInfo<BaseHouseInfo> getSignalContinuationHouseList(Page page, BaseHouseInfo baseHouseInfo) {
        List<BaseHouseInfo> list = new ArrayList<>();
        if (StringUtils.isEmpty(baseHouseInfo.getBuildNo())) {
            return new PageInfo<>(list);
        }
        BaseBuildInfo baseBuildInfo = baseBuildInfoMapper.getInfoById(baseHouseInfo.getBuildNo());
        if (baseBuildInfo == null) {
            return new PageInfo<>(list);
        }
        baseHouseInfo.setBuildAttr(baseBuildInfo.getBuildAttr());
        baseHouseInfo.setBuildType(baseBuildInfo.getBuildType());
        return getContinuationHouseList(page, baseHouseInfo);
    }

    /**
     * 查询续交模式下拉列表
     *
     * @param depModeInfo 查询信息
     * @return 续交下拉列表
     */
    @Override
    public List<DepModeInfo> getModeList(DepModeInfo depModeInfo) {
        if (StringUtils.isEmpty(depModeInfo.getHouseNature()) || StringUtils.isEmpty(depModeInfo.getHouseType()) || StringUtils.isEmpty(depModeInfo.getElevator())) {
            //如果必填项为空，则返回空集合
            return new ArrayList<>();
        }
        if (StringUtils.isNotEmpty(depModeInfo.getBuildId())) {
            //如果自然幢ID非空，则为单个自然幢查询续交列表
            BaseBuildInfo baseBuildInfo = baseBuildInfoMapper.getInfoById(depModeInfo.getBuildId());
            if (baseBuildInfo == null) {
                //如果自然幢为空，则返回空集合
                return new ArrayList<>();
            }
            depModeInfo.setBuildType(baseBuildInfo.getBuildType());
            depModeInfo.setBiuldStructure(baseBuildInfo.getBuildAttr());
        }
        List<DepModeInfo> depModeInfoList = depModeInfoMapper.selectByAllChange(depModeInfo);
        for (DepModeInfo dep : depModeInfoList) {
            if (NumStrEnum.ONE.getNum().equals(dep.getState())) {
                dep.setState("true");
            } else {
                dep.setState("false");
            }
        }
        return depModeInfoList;
    }

    /**
     * 查询续交待审核列表
     *
     * @param page          分页信息
     * @param baseHouseInfo 查询实体
     * @return 续交待审核列表
     */
    @Override
    public PageInfo<BaseHouseInfo> getAuditList(Page page, BaseHouseInfo baseHouseInfo) {
        //查询登陆账号管理下待审核业务ID和管理区域
        Map<String, String> map = flowUtil.getBussIdAndZoneCodeByOperNo(FlowTypeEnum.DEPOSIT_CONTINUATION.getType());
        List<BaseHouseInfo> list = new ArrayList<>();
        if (null != map) {
            result.selectParm(map, baseHouseInfo);
            PageHelper.startPage(page.getPageNum(), page.getPageSize());
            list = depositContinuationMapper.getAuditList(baseHouseInfo);
        }
        return new PageInfo<>(list);
    }

    /**
     * 续交审核
     *
     * @param depositAuditRequest list    审核ID
     *                            opinion 审批意见
     *                            mark    审批通过 audit_pass
     *                            审批否决 audit_veto
     *                            审批退回 audit_back
     * @return 操作结果
     */
    @Override
    public CommonResult audit(DepositAuditRequest depositAuditRequest) {
        List<String> list = depositAuditRequest.getList();
        if (list == null || list.isEmpty()) {
            return CommonResult.ResponseResult(0, "请选择待审核的房间");
        }
        for (String businessId : list) {
            //返回审批状态
            String auditState = flowAddAuditUtil.audit(businessId, depositAuditRequest.getOpinion(), depositAuditRequest.getMark(), null);
            if (StringUtils.isBlank(auditState)) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
            if (!FlowStateEnum.IN_AUDIT.getState().equals(auditState)) {
                DepReqListInfo depReqListInfo = depReqListInfoMapper.getInfo(businessId);
                //续交 ，修改dep_notice表
                dealDepNotice(depReqListInfo.getHouseId(), auditState, null, null);
                if (FlowStateEnum.PASS.getState().equals(auditState)) {
                    int num = depositAuditMapper.updateConState(businessId, auditState, ShiroUserUtil.getUserName());
                    if (num == NumberEnum.ZERO.getNum()) {
                        throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
                    }
                    updateDepReq(depReqListInfo);
                } else {
                    int num = baseHouseInfoMapper.changeFlowInProgress(NumStrEnum.ZERO.getNum(), depReqListInfo.getHouseId());
                    if (num == NumberEnum.ZERO.getNum()) {
                        throw new CourseException(ShiroResultEnum.FAIL.getCode(), "修改房屋状态失败");
                    }
                    int count = depositAuditMapper.updateState(businessId, auditState, ShiroUserUtil.getUserName());
                    if (count == NumberEnum.ZERO.getNum()) {
                        throw new CourseException(ShiroResultEnum.FAIL.getCode(), "修改审核状态失败");
                    }
                }
            }
        }
        return CommonResult.ResponseResult(1);
    }

    /**
     * 处理
     *
     * @param houseId    房间ID
     * @param auditState 状态
     */
    private void dealDepNotice(String houseId, String auditState, String no, String validDate) {
        DepNotice depNotice = new DepNotice();
        String state = FlowStateEnum.PASS.getState().equals(auditState) ? "3" : FlowStateEnum.VETO.getState().equals(auditState) ? "4" : "2";
        depNotice.setState(state);
        depNotice.setHouseId(houseId);
        depNotice.setNo(no);
        depNotice.setValidDate(validDate);
        depositContinuationMapper.updateState(depNotice);
    }

    /**
     * 续交查询列表
     *
     * @param page          分页信息
     * @param baseHouseInfo 查询实体
     * @return 续交待审核列表
     */
    @Override
    public PageInfo<BaseHouseInfo> searchAuditList(Page page, BaseHouseInfo baseHouseInfo) {
        baseHouseInfo.setZoneCode(zoneCodeUtil.getZoneCode());
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseHouseInfo> list = depositContinuationMapper.searchAuditList(baseHouseInfo);
        return new PageInfo<>(list);
    }

    /**
     * 查询续交撤销列表
     *
     * @param page          分页信息
     * @param baseHouseInfo 查询实体
     * @return 续交撤销列表
     */
    @Override
    public PageInfo<BaseHouseInfo> getRevocationList(Page page, BaseHouseInfo baseHouseInfo) {
        baseHouseInfo.setZoneCode(zoneCodeUtil.getZoneCode());
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseHouseInfo> list = depositContinuationMapper.getRevocationList(baseHouseInfo);
        return new PageInfo<>(list);
    }

    /**
     * 续交撤销查询
     *
     * @param page          分页信息
     * @param baseHouseInfo 查询实体
     * @return 续交撤销查询
     */
    @Override
    public PageInfo<BaseHouseInfo> searchRevocationList(Page page, BaseHouseInfo baseHouseInfo) {
        baseHouseInfo.setZoneCode(zoneCodeUtil.getZoneCode());
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseHouseInfo> list = depositContinuationMapper.searchRevocationList(baseHouseInfo);
        return new PageInfo<>(list);
    }

    /**
     * 续交撤销
     *
     * @param list 撤销ID集合
     * @return 撤销结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult revocation(List<String> list) {
        for (String id : list) {
            DepReqListInfo depReqListInfo = depReqListInfoMapper.getInfo(id);
            if (!NumStrEnum.THREE.getNum().equals(depReqListInfo.getState())) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), "该数据已记账或撤销，请刷新页面重试");
            }
            DepReq depReq = depReqMapper.getInfo(depReqListInfo.getDepReqId());
            //增加撤销表
            String uuid = UUIDUtil.getUUID();
            depositApplyService.revocation(depReq, "0", uuid);
            //增加撤销详情表
            DepRevocatDetail depRevocatDetail = depositApplyService.revocationList(uuid, depReqListInfo);
            depReqListInfoMapper.dep_revocat_detailDdInsert(depRevocatDetail);
            //acckeep 修改状态
            int num = accKeepAccountMapper.updateState("0", depReq.getNo());
            if (num == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), "修改记账表操作失败");
            }
            //dep_req 修改状态
            int count = depReqMapper.updateState(depReqListInfo.getDepReqId(), "0");
            if (count == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), "修改申请表操作失败");
            }
            //dep_req_list  修改状态
            num = depReqListInfoMapper.updateStateByDepReqState(depReqListInfo.getDepReqId());
            if (num == 0) {
                throw new CourseException(201, "修改申请详情表操作失败");
            }
            int i = baseHouseInfoMapper.changeFlowInProgress("0", depReqListInfo.getHouseId());
            if (i == 0) {
                throw new CourseException(201, "修改房屋表操作失败");
            }
            //修改通知表
            int j = depositContinuationMapper.resetModeType(depReqListInfo.getHouseId());
            if (j == 0) {
                throw new CourseException(201, "修改通知表操作失败");
            }
        }
        return CommonResult.ResponseResult(1);
    }

    /**
     * 修改缴存申请表
     *
     * @param depReqListInfo 缴存维护信息
     */
    private void updateDepReq(DepReqListInfo depReqListInfo) {
        BaseHouseInfo baseHouseInfo = baseHouseInfoMapper.getInfo(depReqListInfo.getHouseId());
        DepReq depReq = depReqMapper.getInfo(depReqListInfo.getDepReqId());
        String no = DepositUtil.getNo(NumberEnum.ONE.getNum().toString());
        depReq.setNo(no);
        dealDepNotice(depReqListInfo.getHouseId(), "2", no, null);
        int num = depReqMapper.updateByPrimaryKeySelective(depReq);
        if (num == 0) {
            throw new CourseException(ShiroResultEnum.FAIL.getCode(), "添加续交申请编号失败");
        }
        successDep(depReq, baseHouseInfo);
    }

    /**
     * 重置交存模式
     *
     * @param houseId 房间ID
     * @return 重置结果
     */
    @Override
    public CommonResult resetModeType(String houseId) {
        int i = depositContinuationMapper.resetModeType(houseId);
        return CommonResult.ResponseResult(i);
    }

    /**
     * 维护交存模式
     *
     * @param list 维护的交存模式房间集合
     * @return 维护结果
     */
    @Override
    public CommonResult setModeType(List<DepNotice> list) {
        /**
         * 计算续交金额
         */
        for (DepNotice depNotice : list) {
            BaseHouseInfo baseHouseInfo = baseHouseInfoMapper.getInfo(depNotice.getHouseId());
            baseHouseInfo.setFirstMode(depNotice.getModeType());
            //计算续交金额
            BigDecimal dueAmount = calculateAmount.calculateDueAmount(baseHouseInfo);
            depNotice.setPayAmount(dueAmount);
            depNotice.setState(NumStrEnum.ONE.getNum());
            depNotice.setEnding(NumStrEnum.ZERO.getNum());
        }
        int num = depositContinuationMapper.addDepNotice(list);
        return CommonResult.ResponseResult(num);
    }

    /**
     * 续交申请
     *
     * @param depositContinuation 续交房间集合
     * @return 续交结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult apply(DepositContinuation depositContinuation) {
        List<BaseHouseInfo> list = depositContinuation.getList();
        if (list == null || list.isEmpty()) {
            return CommonResult.ResponseResult(0, "请选择续交的房间");
        }
        for (BaseHouseInfo info : list) {
            BaseHouseInfo baseHouseInfo = baseHouseInfoMapper.getInfo(info.getId());
            //房屋状态
            baseHouseInfoService.houseState(baseHouseInfo);
            int no = depReqListInfoMapper.selecthouseDep(info.getId(), info.getOwnerId());
            if (no > 0) {
                return CommonResult.ResponseResult(0, baseHouseInfo.getHouseSite() + "已处理，请刷新页面重试");
            }
            if (FlowTypeEnum.DEPOSIT_CONTINUATION.getType().equals(baseHouseInfo.getFlowInProgress())) {
                return CommonResult.ResponseResult(0, baseHouseInfo.getHouseSite() + "正在续交");
            }
            /**
             * 添加房屋状态
             */
            baseHouseInfo.setFlowInProgress(FlowTypeEnum.DEPOSIT_CONTINUATION.getType());
            int num = baseHouseInfoMapper.update(baseHouseInfo);
            if (num == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
            baseHouseInfo.setModeType(info.getModeType());
            baseHouseInfo.setPayAmount(info.getPayAmount());
            baseHouseInfo.setName(info.getName());
            baseHouseInfo.setOwnerId(info.getOwnerId());
            //处理续交详情表
            dealDepApply(baseHouseInfo, depositContinuation.getValidDate());
        }
        return CommonResult.ResponseResult(1);
    }


    /**
     * 处理续交详情表
     *
     * @param baseHouseInfo 续交房间信息
     */
    private void dealDepApply(BaseHouseInfo baseHouseInfo, String validDate) {
        DepReqListInfo depReqListInfo = new DepReqListInfo();
        String depReqListId = UUIDUtil.getUUID();
        String depReqId = UUIDUtil.getUUID();
        depReqListInfo.setDepReqId(depReqId);
        depReqListInfo.setId(depReqListId);
        depReqListInfo.setCreater(ShiroUserUtil.getUserName());
        String flowState = flowAddAuditUtil.initFlow(depReqListId, FlowTypeEnum.DEPOSIT_CONTINUATION.getType(), null);
        if ((NumStrEnum.TWO.getNum()).equals(flowState)) {
            depReqListInfo.setRecDate(LocalDate.now().toString());
        }
        depReqListInfo.setBuildId(baseHouseInfo.getBuildNo());
        depReqListInfo.setHouseId(baseHouseInfo.getId());
        depReqListInfo.setDepMode(baseHouseInfo.getModeType());
        depReqListInfo.setFlowState(flowState);
        depReqListInfo.setDepDate(LocalDate.now().toString());
        depReqListInfo.setPayAmount(baseHouseInfo.getPayAmount());
        depReqListInfo.setDeferAccr(BigDecimal.ZERO);
        depReqListInfo.setState(flowState != null && flowState.equals(NumStrEnum.TWO.getNum()) ? NumStrEnum.THREE.getNum() : NumStrEnum.ONE.getNum());
        //续交
        depReqListInfo.setDepType(NumStrEnum.THREE.getNum());
        depReqListInfo.setOwnerNo(baseHouseInfo.getOwnerId());
        int num = depReqListInfoMapper.insert(depReqListInfo);
        if (num == 0) {
            throw new CourseException(ShiroResultEnum.FAIL.getCode(), "添加缴存详情表操作失败");
        }
        dealDepNotice(baseHouseInfo.getId(), flowState, null, null);
        //处理申请表
        dealDepReq(depReqId, depReqListInfo, baseHouseInfo, flowState, validDate);
    }

    /**
     * 处理申请表
     *
     * @param depReqId       申请表ID
     * @param depReqListInfo 续交详情
     * @param baseHouseInfo  房间详情
     * @param flowState      审核状态
     * @param validDate      申请有效日期
     */
    private void dealDepReq(String depReqId, DepReqListInfo depReqListInfo, BaseHouseInfo baseHouseInfo, String flowState, String validDate) {
        BaseBuildInfo baseBuildInfo = baseBuildInfoMapper.getInfo(depReqListInfo.getBuildId());
        DepReq depReq = new DepReq();
        depReq.setBankCode(baseBuildInfo.getBankCode());
        depReq.setId(depReqId);
        depReq.setType("0");
        depReq.setCorpType(DepositEnum.SELF_DEPOSIT.getCode());
        depReq.setReqOper(baseHouseInfo.getName());
        depReq.setStep(NumStrEnum.THREE.getNum());
        depReq.setTotalNum(1);
        depReq.setFundAmount(depReqListInfo.getPayAmount());
        depReq.setTotalAmount(depReqListInfo.getPayAmount());
        depReq.setDeferAccr(BigDecimal.ZERO);
        depReq.setReqDate(LocalDate.now().toString());
        depReq.setValidDate(validDate);
        String userName = ShiroUserUtil.getUserName();
        depReq.setCreater(userName);
        depReq.setModifier(userName);
        depReq.setState(NumStrEnum.ONE.getNum());
        if (NumStrEnum.TWO.getNum().equals(flowState)) {
            String no = DepositUtil.getNo(NumberEnum.ONE.getNum().toString());
            depReq.setNo(no);
            //审核通过，记账
            successDep(depReq, baseHouseInfo);
            dealDepNotice(baseHouseInfo.getId(), flowState, no, validDate);
        }
        int count = depReqMapper.insert(depReq);
        if (count == NumberEnum.ZERO.getNum()) {
            throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
        }
    }

    /**
     * 续交审核通过，记账
     */
    private void successDep(DepReq depReq, BaseHouseInfo baseHouseInfo) {
        BaseBuildInfo baseBuildInfo = baseBuildInfoMapper.getInfo(baseHouseInfo.getBuildNo());
        AccKeepAccount accKeepAccount = new AccKeepAccount();
        accKeepAccount.setReqName(depReq.getReqOper());
        accKeepAccount.setBusiNo(depReq.getNo());
        accKeepAccount.setBusiType("311");
        accKeepAccount.setCreateTime(LocalDate.now().toString());
        accKeepAccount.setCreater(ShiroUserUtil.getUserName());
        accKeepAccount.setBankCode(depReq.getBankCode());
        accKeepAccount.setPayAmount(depReq.getTotalAmount());
        accKeepAccount.setAccountState(NumStrEnum.ZERO.getNum());
        accKeepAccount.setState(NumStrEnum.ONE.getNum());
        accKeepAccount.setSpecialAccount("325");
        accKeepAccount.setVaildDate(depReq.getValidDate());
        accKeepAccount.setRegionId(baseBuildInfo.getRegionNo());
        accKeepAccount.setGrantreqNum(depReq.getNo());
        accKeepAccount.setRemark(baseHouseInfo.getHouseSite() + "续交");
        int count = accKeepAccountMapper.insert(accKeepAccount);
        if (count == NumberEnum.ZERO.getNum()) {
            throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
        }
    }
}
